﻿using SharpML.Api.External;
using SharpML.Api.Interfaces;
using System;

namespace SharpML.Api.Implementation
{
    /// <summary>
    /// Accessor class that provides psuedo-random generation services
    /// </summary>
    public static class Randomized
    {
        /// <summary>
        /// The singleton instance
        /// </summary>
        public static IRandom Default;

        static Randomized()
        {
            Reset();
        }

        /// <summary>
        /// Recreates the RNG concrete implementation, reseeding the new instance
        /// </summary>
        public static void Reset()
        {
            // Instantiate RNG
            SimpleRNG rng = new SimpleRNG();

            // Store RNG
            Randomized.Default = rng;

            // Use one random to initialize the other, lol
            var random = new Random( Guid.NewGuid().GetHashCode() );
            
            // Set the seed
            rng.SetSeed( (uint)random.Next() );
        }
    }
}
